package com.midea.ai.air.ui.more;

import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseActivity;
import com.midea.ai.air.ui.more.adapter.MoreLoggingAdapter;
import com.midea.ai.air.ui.more.data.MoreLoggingItem;
import com.midea.ai.air.view.ListViewForScrollView;
import com.midea.ai.air.view.MyTitleBar;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hww on 2016/3/24.
 * 更多-设置-智能联动日志
 */
public class MoreSettingBrainpowerLogging extends BaseActivity implements View.OnClickListener {

    private TextView actionbar_left_tv;
    private List<MoreLoggingItem> mList_dates = new ArrayList<>();
    private ListViewForScrollView mListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_moresettingbrainpowerlogging);

        init();
    }

    MyTitleBar myTitleBar;

    private void init() {
        myTitleBar = new MyTitleBar(this);
        myTitleBar.setActionBar_center(R.string.more_setting_brainpower_logging);
        myTitleBar.setActioBar_left(true, R.drawable.register_titler_left, R.string.more_setting_brainpower);
        myTitleBar.setActionBar_right_iv(true, R.drawable.more_logging_delete);

        actionbar_left_tv = (TextView) findViewById(R.id.actionbar_tv_left);
        actionbar_left_tv.setTextColor(getResources().getColor(R.color.electric_histogram));
        mListView = (ListViewForScrollView) findViewById(R.id.more_setting_brianpwoer_logging_listView);
        create_Delete_Logging_Dialog();

        mList_dates.add(new MoreLoggingItem(R.drawable.more_setting_branpower_01, "我的家 20:00 打开空调", "2015年12月30日 20:00  执行成功"));
        mList_dates.add(new MoreLoggingItem(R.drawable.more_setting_branpower_04, "我的家 室外温度高于100 打开净化器", "2015年12月30日 20:00  执行成功"));

        mListView.setAdapter(new MoreLoggingAdapter(MoreSettingBrainpowerLogging.this, mList_dates));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.actionbar_left_relativeLayout:

                finish();
                break;
            case R.id.actionbar_iv_right:
                delete_Dialog.show();
                break;
        }
    }

    private Dialog delete_Dialog;

    private void create_Delete_Logging_Dialog() {
        View view_delete_logging = LayoutInflater.from(MoreSettingBrainpowerLogging.this)
                .inflate(R.layout.dialog_delete_logging_item, null);
        delete_Dialog = new Dialog(MoreSettingBrainpowerLogging.this, R.style.my_activate_dialog);
        delete_Dialog.setCancelable(true);
        delete_Dialog.setCanceledOnTouchOutside(false);
        delete_Dialog.setContentView(view_delete_logging);
        TextView dialog_cancel = (TextView) view_delete_logging.findViewById(R.id.dialog_delete_logging_item_cancel);
        TextView dialog_confirm = (TextView) view_delete_logging.findViewById(R.id.dialog_delete_logging_item_confirm);
        dialog_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (delete_Dialog != null && delete_Dialog.isShowing()) {
                    delete_Dialog.dismiss();
                }
            }
        });
        dialog_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (delete_Dialog != null && delete_Dialog.isShowing()) {
                    delete_Dialog.dismiss();
                }
            }
        });
    }

}
